package com.yanyu.space.common.core.exception;

import com.yanyu.space.common.core.bean.enums.IRCode;
import com.yanyu.space.common.core.bean.web.RCode;

/**
 * @author yanyu
 */
public class ServiceException extends RuntimeException implements IRCode{

    private Integer code = RCode.FAIL.getCode();

    public ServiceException() {
        super(RCode.FAIL.getMsg());
    }

    public ServiceException(IRCode rCode) {
        super(rCode.getMsg());
        this.code = rCode.getCode();
    }

    public ServiceException(IRCode rCode, Throwable cause) {
        super(rCode.getMsg(), cause);
        this.code = rCode.getCode();
    }

    public ServiceException(IRCode rCode, String ...param) {
        super(String.format(rCode.getMsg(), param));
        this.code = rCode.getCode();
    }

    public ServiceException(IRCode rCode, Throwable cause, String ...param) {
        super(String.format(rCode.getMsg(), param), cause);
        this.code = rCode.getCode();
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return getMessage();
    }
}
